package com.ayu.scalalearn.chapter06

/**
  * @Author 徐林玉
  * @Description Test11TraitMixin
  * @Date 2022/7/29 14:54
  * @Version 1.0
  */
object Test11TraitMixin {

  def main(args: Array[String]): Unit = {

    var stu1 = new StudentTest11;
    stu1.hello()
    stu1.learn()
    stu1.learn()
    stu1.learn()

    println("================")


    //特质混入
    var stu2 = new StudentTest11 with Telent {
      override def singing(): Unit = {
        println("this student cannot singing well")
      }

      override def dancing(): Unit = {

        println("this student can dancing well")
      }
    }

    stu2.hello()

    stu2.learn()

    stu2.dancing()

    stu2.singing()
  }

}


trait Knowledge {

  var amount: Int = 0

  def learn(): Int
}

trait Telent {

  def singing(): Unit

  def dancing(): Unit
}


class StudentTest11 extends Knowledge {

  var name: String = _
  var age: Int = _

  def hello(): Unit = {

    println("student say hello to you")
  }

  override def learn(): Int = {

    amount += 1
    println(" Students knowledge has been increased : " + amount)

    amount
  }
}
